package com.neolix.watch.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.neolix.watch.R;

public class MainMenuAdapter extends BaseAdapter {
    private final int height;
    private Context mContext;

    private Integer[] menuPictures;
    private String[] menuItemStrings;

    public MainMenuAdapter(Context context, int height) {
        this.height = height;
        mContext = context;
        menuItemStrings = mContext.getResources().getStringArray(R.array.main_item_text);
        menuPictures =
                new Integer[]{
                        R.drawable.selector_menu_pay,
                        R.drawable.selector_menu_remaind,
                        R.drawable.selector_menu_weather,
                        R.drawable.selector_menu_watch,
                        R.drawable.selector_menu_search,
                        R.drawable.selector_menu_setting,
                };
    }

    public int getCount() {
        return menuPictures.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(R.layout.view_main_menu_item, null);
            ImageView iv = (ImageView) convertView.findViewById(R.id.item_imageView);
            TextView tv = (TextView) convertView.findViewById(R.id.item_textView);
            iv.setImageResource(menuPictures[position]);
            tv.setText(menuItemStrings[position]);

        } else {
            ImageView iv = (ImageView) convertView.findViewById(R.id.item_imageView);
            TextView tv = (TextView) convertView.findViewById(R.id.item_textView);
            iv.setImageResource(menuPictures[position]);
            tv.setText(menuItemStrings[position]);
        }

        AbsListView.LayoutParams param = new AbsListView.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, height);
        convertView.setLayoutParams(param);

        return convertView;
    }
}
